<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.team5.admin.Admin"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page session="true" %>
<%
	WebHandler web = new WebHandler(request, response, out);
	AdminItem loginInfo = (AdminItem)session.getAttribute("ADMIN_INFO");
	
	// 로그인 정보가 없을 경우 로그인 페이지로 이동
	if (loginInfo == null) {
		web.goPage("/italia/login.jsp", "로그인이 필요합니다");
		return;
	}
%>
<%
	String seq = request.getParameter("seq");

	if (!PatternChecker.isValue(seq)) {
		out.print("<script type='text/javascript'>alert('파라미터가 없습니다.');history.back();</script>");
		return;
	}
	if (!PatternChecker.isNum(seq)) {
		out.print("<script type='text/javascript'>alert('파라미터가 부정확합니다.');history.back();</script>");
		return;
	}

	int admin_seq = Integer.parseInt(seq);

%>
<%@ include file="../dbcon.jsp"%>
<%
	
	/** 관리자 데이터 조회 */
	Admin admin = new Admin();
	AdminItem item = admin.viewAdmin(admin_seq);
	
	if (item == null) {
		out.print("<script type='text/javascript'>alert('데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.')");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h1>관리자 정보 보기</h1>
		</div>
		
		<form id="frmAdminView" class="form-horizontal" role="form" method="post" action="">
			
			<!-- 관리자 계정 자동입력 -->
			<input type="hidden" name="seq" value="<%=seq%>">
			
			<fieldset>
				
				<!-- 입력양식 -->
				<div class="form-group">
					<label for="admin_id" class="col-md-2 control-label">아이디</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getAdmin_id()%></p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_pw" class="col-md-2 control-label">비밀번호</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getAdmin_pw()%></p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_level" class="col-md-2 control-label">레벨</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getAdmin_level()%> level</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_comment" class="col-md-2 control-label">코멘트</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getAdmin_comment()%></p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="reg_date" class="col-md-2 control-label">등록일자</label>
					<div class="col-md-10">
						<p class="form-control-static"><td><%=item.getReg_date().substring(0, 4)%>-<%=item.getReg_date().substring(4, 6)%>-<%=item.getReg_date().substring(6, 8)%>&nbsp;<%=item.getReg_date().substring(8, 10)%>:<%=item.getReg_date().substring(10, 12)%>:<%=item.getReg_date().substring(12, 14)%></td></p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="edit_date" class="col-md-2 control-label">수정일자</label>
					<div class="col-md-10">
						<p class="form-control-static"><td><%=item.getEdit_date().substring(0, 4)%>-<%=item.getEdit_date().substring(4, 6)%>-<%=item.getEdit_date().substring(6, 8)%>&nbsp;<%=item.getEdit_date().substring(8, 10)%>:<%=item.getEdit_date().substring(10, 12)%>:<%=item.getEdit_date().substring(12, 14)%></td></p>
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-4">
								<a href="listAdmin.jsp" class="btn btn-primary btn-block">목록보기</a>
							</div>
							<div class="col-md-4">
								<button type="submit" id="edit" formaction="editAdmin.jsp" 
									formmethod="post" class="btn btn-info btn-block">수정하기</button>
							</div>
							<div class="col-md-4">
								<button type="submit" id="delete" formaction="deleteAdminOk.jsp" 
									formmethod="post" class="btn btn-danger btn-block">삭제하기</button>
							</div>
						</div>
					</div>
				</div>
				
			</fieldset>
		</form>
	</div>
	<% DBHandler.disconnect(); %>
	<!-- Javascript -->
	<script src="/italia/assets/js/jquery.js"></script>
	<script src="/italia/assets/js/bootstrap.min.js"></script>
	
	<script type="text/javascript">
		$(function() {
			// id 속성이 "delete"인 요소에 대한 click이벤트
			$("#delete").click(function() {
				// 사용자에게 물어본다.
				if (!confirm("정말 삭제하시겠습니까?")) {
					// 취소를 선택한 경우 처리 둥단
					return false;
				}
			});
		});
	</script>
  </body>
</html>